package com.duobao.view;
import java.awt.*;

import javax.swing.*;

import com.duobao.game.DuobaoSwingLaunch;
import com.duobao.server.*;
import com.duobao.uitl.*;

import java.awt.event.*;
import java.lang.reflect.*;

public class Diuqi extends JPanel implements MouseListener{
    DuobaoSwingLaunch game;
    Map heroMap;
    Equip equip;
    JLabel fanhui;
    JLabel fanhuiyouxi;

    JLabel tishi;
    public Diuqi(DuobaoSwingLaunch game, Equip equip)
    {
        this.game=game;
        this.heroMap=Maps.getMap(this.game.hero.getLocation());
        GridLayout gl=new GridLayout(16,1,1,1);
        this.setLayout(gl);
        this.equip = equip;

        setTishi();
        setXiaoguo();



        setFanhui();
        setFanhuiyouxi();
    }
    private void setXiaoguo()
    {
        if(!this.equip.ifHuoBi())
        {
            this.game.hero.getEquip2().remove(equip);
            if(equip.getCategory()==14 || equip.getCategory()==15)
            {
                equip.setVe(this.heroMap.getEquips());
            }
            this.heroMap.getEquips().add(equip);
            equip.setZB(false);
            equip.setDQTime(System.currentTimeMillis());
        }else
        {
            this.heroMap.setHuobi(equip);
            equip.setZB(false);
            equip.setDQTime(System.currentTimeMillis());
        }
        this.game.hero.setFZ();
    }
    private void setTishi() {
        tishi=new JLabel("你把"+equip.getName()+"扔在了地上");
        tishi.setFont(myFont.f2);
        tishi.addMouseListener(this);
        JPanel jp1=new JPanel();
        jp1.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp1.add(tishi);
        this.add(jp1);
    }
    private void setFanhui() {
        fanhui=new JLabel();
        fanhui.addMouseListener(this);
        fanhui.setFont(myFont.f2);
        fanhui.setForeground(Color.BLUE);
        fanhui.setText("<html><u>"+"返回"+"</u></html>");
        JPanel jp3=new JPanel();
        jp3.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp3.add(fanhui);
        this.add(jp3);
    }

    private void setFanhuiyouxi() {
        fanhuiyouxi=new JLabel();
        fanhuiyouxi.addMouseListener(this);
        fanhuiyouxi.setFont(myFont.f2);
        fanhuiyouxi.setForeground(Color.BLUE);
        fanhuiyouxi.setText("<html><u>"+"返回游戏"+"</u></html>");
        JPanel jp4=new JPanel();
        jp4.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
        jp4.add(fanhuiyouxi);
        this.add(jp4);
    }
    private boolean iFText(JLabel jl)
    {
        boolean f=false;
        if(jl==tishi)
        {
            f=true;
        }
        return f;
    }

    public void mouseClicked(MouseEvent e) {
        // TODO Auto-generated method stub
        if(e.getSource()==fanhuiyouxi)
        {
            this.game.setPanel(new MainPanel(this.game,1));
        }else if(e.getSource()==fanhui)
        {
            try {
                this.game.setPanel(new Shuishen(this.game,ZhuangTaiPanel.class.getDeclaredConstructor(DuobaoSwingLaunch.class,Constructor.class,int.class),1));
            }catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }
    }
    public void mouseEntered(MouseEvent e) {
        // TODO Auto-generated method stub
        if(iFText((JLabel)e.getSource()))
        {
            ((JLabel)e.getSource()).setCursor(new Cursor(Cursor.TEXT_CURSOR));
        }
    }
    public void mouseExited(MouseEvent e) {
        // TODO Auto-generated method stub

    }
    public void mousePressed(MouseEvent e) {
        // TODO Auto-generated method stub

    }
    public void mouseReleased(MouseEvent e) {
        // TODO Auto-generated method stub

    }
}
